package acm.广度优先搜索;

import 左哥算法.ch15并查集.UnionFindSet;

import java.util.*;

/**
 * 并查集解法
 */
public class P {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (w==0)return;
            sc.nextLine();
            boolean[][] maze=new boolean[w][h];
            int x=0,y=0;
            for (int i = 0; i < maze.length; i++) {
                char[] chars = sc.nextLine().toCharArray();
                for (int j = 0; j < maze[i].length; j++) {
                    if (chars[j]!='#'){
                        maze[i][j]=true;
                        x=chars[j]=='@'?i:x;
                        y=chars[j]=='@'?j:y;
                    }
                }
            }
            System.out.println(fun(maze,x,y));
        }
    }
    public static int fun(boolean[][] maze,int x,int y){
        UnionFindSet<Node> unionFindSet=new UnionFindSet<>();
        int[][] directions={
                {0,1},
                {0,-1},
                {1,0},
                {-1,0},
        };
        for (int i = 0; i < maze.length; i++) {
            for (int j = 0; j < maze[i].length; j++) {
                if (maze[i][j]){
                    Node curr = new Node(i, j);
                    unionFindSet.init(curr);
                    for (int[] d : directions) {
                        Node node = new Node(i + d[0], j + d[1]);
                        if (node.x>=0&&node.x<maze.length&&node.y>=0&&node.y<maze[0].length&&maze[node.x][node.y]){
                            unionFindSet.union(curr,node);
                        }
                    }
                }
            }
        }
        return unionFindSet.getSetSize(new Node(x,y));
    }
    static class Node{
        int x;
        int y;

        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node node = (Node) o;
            return x == node.x && y == node.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }
}